﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Forums.OfflineStore;
using System.Collections.ObjectModel;
using Microsoft.Forums.ForumsProvider;

namespace Microsoft.Forums.SyncService
{
    public interface ISynchronizationController
    {
        /// <summary>
        /// Event fire when a synchronization of a whole forum is complete
        /// </summary>
        event EventHandler<SynchronizeForumCompletedEventArgs> SynchronizeForumCompleted;

        /// <summary>
        /// Event fire when a synchronization of a thread is complete
        /// </summary>
        event EventHandler<SynchronizeThreadCompletedEventArgs> SynchronizeThreadCompleted;

        /// <summary>
        /// Retrieve a collection of the forums service provider we have available
        /// </summary>
        IList<IForumServiceProvider> ServiceProviders { get; }

        /// <summary>
        /// Gets a collection of all the forums 
        /// </summary>
        /// <param name="brand"></param>
        /// <param name="locale"></param>
        /// <returns></returns>
        IList<Forum> GetAvailableForums(string brand, int locale);

        /// <summary>
        /// Get a collection of all the supported brands
        /// </summary>
        /// <returns>collection of brands</returns>
        IList<String> SupportedBrands { get; }

        /// <summary>
        /// Get a collection of all the supported locales
        /// </summary>
        /// <returns>collection of locales</returns>
        IList<KeyValuePair<int, string>> SupportedLocales { get; }

        /// <summary>
        /// Adds a Forum to the local store.
        /// In order to call this you must pass in the Forum object you want to add and
        /// a ForumPropertySet object which sets the different properties for the Forum
        /// </summary>
        /// <param name="forum">The forum to subscribe to</param>
        /// <param name="propertySet">The user configurable properties for this forum</param>
        void SubscribeToForum(Forum forum, ForumPropertySet propertySet);

        /// <summary>
        /// Remove a Forum (and all associated Post data) from the local store
        /// </summary>
        /// <param name="forumId">The forum to unsubscribe from</param>
        void UnsubscribeFromForum(Guid forumId);

        /// <summary>
        /// This method cancels an asynchronous operation give the forum id involved
        /// </summary>
        /// <param name="forumId">Id of forum involved in asynchrnous operation</param>
        void CancelSynchronization(Guid forumId);

        /// <summary>
        /// Determines whether the specified forum is synchronizing.
        /// </summary>
        /// <param name="forumId">The forum id.</param>
        /// <returns>
        /// 	<c>true</c> if the specified forum  is synchronizing; otherwise, <c>false</c>.
        /// </returns>
        bool IsSynchronizing(Guid forumId);

        /// <summary>
        /// Synchronize all subscribe Forums which are in the database.
        /// This sync uses the forum table's LastSyncedOn field to determine date to get update from
        /// </summary>
        /// <param name="forumId"></param>
        /// <returns>A summary object which indicates what was synchronized</returns>
        SynchronizeForumSummary SynchronizeForum(Guid forumId);

        /// <summary>
        /// Synchronize the given forum asynchronously.
        /// </summary>
        /// <param name="forumId">Id of the forum to synchronize</param>
        void SynchronizeForumAsync(Guid forumId);

        /// <summary>
        /// This deletes all data in that Forum which is stored locally.
        /// It will then synchronize all data for that Forum which has been updated since 
        /// the forum's SynchFrom value which is store in the database
        /// </summary>
        /// <param name="forumId"></param>
        void ResetForum(Guid forumId);


        /// <summary>
        /// Processes the pending action queue. Runs throughs each items in the queue and processes it 
        /// and either updates its status or removes it from the queue
        /// </summary>
        void ProcessPendingActionQueue();
    }
}
